package com.softcomputer.rpt.ejb;

import com.softcomputer.rpt.entity.ExCourse;
import java.io.Serializable;
import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@Stateless
public class CoursesDBSession implements Serializable {

    @Resource(mappedName = "jms/NotificationQueue")
    private Queue notificationQueue;
    @Resource(mappedName = "jms/NotificationQueueFactory")
    private ConnectionFactory notificationQueueFactory;
    @PersistenceContext(unitName = "Exchanger")
    private EntityManager em;
    private static final Log LOG = LogFactory.getLog(ExchangeSession.class);

    public void saveCourseToDatabase(ExCourse exCourse) {

        try {
            em.persist(exCourse);
        } catch (Exception exception) {
            LOG.error("Unable to persist excourse: " + exception.getMessage());
        }
    }
}